import Vue from 'vue'
import VueRouter from 'vue-router'
import Store from '@/store'
// import Home from '../views/Home.vue'
const Home = () => import('@/views/home')
const Layout = () => import('@/views/layout')
const Member = () => import('@/views/member')
const ShopCar = () => import('@/views/shopcar')
const Search = () => import('@/views/search')

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '/',
        redirect: '/home'
      },
      {
        path: '/home',
        name: 'home',
        component: Home
      },
      {
        path: '/member',
        name: 'member',
        component: Member
      },
      {
        path: '/search',
        name: 'search',
        component: Search
      },
      {
        path: '/shopcar',
        name: 'shopcar',
        component: ShopCar
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  if (to.name === 'home') {
    Store.commit('changeBackTextShow' , false)
  } else {
    Store.commit('changeBackTextShow' , true)
  }
  if (to.name === 'shopcar') {
    Store.commit('changeIsShow', false)
    // Store.state.isShow = false
  } else {
    Store.commit('changeIsShow', true)
    // Store.state.isShow = true
  }
  next()
})
export default router
